﻿using ITXHWEB.Models;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Web.Mvc;
using WPFExcelReport;
using WPFExcelReport.Helpers;
using ITXHWEB.Infrastructure;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace ITXHWEB.Controllers
{
    public partial class ABARTEController
    {


        [ChildActionOnly]
        public ActionResult SMENDVALUE(string returnUrl)
        {
            ModelState.Clear();
            ViewBag.ReturnUrl = returnUrl;
            if(MABF.ABES==null)
            { 
                MABF.IsGotABE = true;
                return PartialView();
            }
            MABF.MABE = null;
            var result = MABF.ABES.Where(p => p.IsGet == false).OrderBy(p => p.MSETID);
            foreach (var m in result)
            {
                MABF.MABE = m;
            }
            if(MABF.MABE==null)
            {
                MABF.IsGotABE = true;
                return PartialView();
            }
            return PartialView(MABF.MABE);
        }
        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult SMENDVALUE(ABARTEModel model, string returnUrl)
        {
            try
            {
                if (MABF.MABE != null)
                {
                    MABF.MABE.MNOWTXTV = model.MNOWTXTV;
                    MABF.MABE.IsGet = true;
                }
                    
                Dictionary<string, object> BDEV = new Dictionary<string, object>();                
                PM["KRS"]=MABF.KRS;
                PM["LFD"] = MABF.LFD;
                PM["POS"] = MABF.POS;
                PM["STEP"] = MABF.FSTEP;
                PM["MKRS"] = MABF.MAM.MKRS;
                PM["MLFD"] = MABF.MAM.MLFD;
                PM["MPOS"] = MABF.MAM.MPOS;
                BDEV[MABF.MABE.MSETID] = MABF.MABE.MNOWTXTV;
                PM["BDEV"] = BDEV;
                VHP.ABP.GETABEAV(PM); 
            }
            catch (Exception ex)
            {
                //VKPAUF = ex.Message;
                Tracer.Error(ex.StackTrace, ex);
            }
            return RedirectToAction(MAPP, MAPP);
        }

    }
}
